using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Wingyong200 : SkillBasic
{
    public float CD;
    private float CDtime;
    GameObject playerobject;
    PlayerBasic player;
    Yongcontrol yong;
    Animator animator;
    GameObject attack;
    PlayerAttack playerattack;
    Rigidbody2D myRigidbody;
    public float damageratio;
    public int skilltimes;
    bool isskilling;
    // Start is called before the first frame update
    void Start()
    {
        player = GetComponentInParent<PlayerBasic>();
        yong = GetComponentInParent<Yongcontrol>();
        animator = GetComponentInParent<Animator>();
        attack = GameObject.FindWithTag("Attack");
        
        playerattack = attack.GetComponent<PlayerAttack>();
        myRigidbody = GetComponentInParent<Rigidbody2D>();
        WingYongCD.CD = CD;
        WingYongCD.CDCurrent = 0;
        isskilling = false;
    }
    void Skillend()
    {
        player.movable = true;
        //player.attackable = true;
        animator.SetBool("yong", false);
        playerattack.damageratio = 1;
        yong.times = 0;
        myRigidbody.gravityScale = PlayerData.fly ? 0 : 10;
        isskilling = false;
        playerattack.wingyong200 = false;
    }
    void Skill()
    {
        player.movable = false;
        //player.attackable = false;
        animator.SetBool("yong", true);
        animator.SetTrigger("yong1");
        playerattack.damageratio = damageratio;
        myRigidbody.gravityScale = 0;
        isskilling = true;
        playerattack.wingyong200 = true;

    }
    void Update()
    {
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
            WingYongCD.CDCurrent = CDtime;
        }
        if (Input.GetKeyDown(KeyCode))
        {
            if (CDtime <= 0 && player.movable)
            {
                Skill();
                CDtime = CD;
            }
        }
        if (yong.times == skilltimes || (player.stifftimeex > 0 && isskilling))
        {
            Skillend();

        }
        if (isskilling)
        {
            myRigidbody.velocity = Vector3.zero;


        }
    }
}
